<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.*" %>
<%@ page import="weaver.file.*" %>
<%@ page import="weaver.hrm.*" %>
<%@page import="weaver.systeminfo.SystemEnv"%>
<%@page import="weaver.email.service.MailMobileService"%>
<%@page import="com.weaver.formmodel.mobile.manager.MobileUserInit"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="com.weaver.formmodel.util.DateHelper"%>
<%
out.clearBuffer();
request.setCharacterEncoding("UTF-8");
User user = MobileUserInit.getUser(request,response);
FileUpload fu = new FileUpload(request); 
JSONObject jsonObject = new JSONObject();

String uploadname = Util.null2String(fu.getParameter("uploadname"));
String uploaddata = Util.null2String(fu.getParameter("uploaddata"));
if(uploaddata.indexOf("base64,")!=-1){
	uploaddata = uploaddata.substring(uploaddata.indexOf("base64,")+"base64,".length());
}
String fileindex = Util.null2String(fu.getParameter("fileindex"));
String fileuuid = Util.null2String(fu.getParameter("fileuuid"));
String key = "fielduuid_"+user.getUID();
String olduuid = Util.null2String(application.getAttribute(key));
if(fileuuid.equals(olduuid)){
	out.println("<script>parent.checkIsSubmitAndGoBack()</script>");
	return;
}
application.setAttribute(key,fileuuid);

jsonObject.put("uploadname",uploadname);
String remoteAddr=Util.null2String(fu.getRemoteAddr());
MailMobileService mobileService=new MailMobileService();
Map map = mobileService.uploadFilesToEmail(uploaddata, uploadname, user);
String docid=(String)map.get("docid");
String filename=(String)map.get("filename");
String filesize=(String)map.get("filesize");

jsonObject.put("docid",docid);
jsonObject.put("fileuuid",fileuuid);
jsonObject.put("filename",filename);
jsonObject.put("filesize",filesize);



int size = Util.getIntValue(filesize,0);
String fileSizeName="";
DecimalFormat df=new DecimalFormat("#.##");
if(size>(1024*1024))
	fileSizeName=df.format(size/(1024.0*1024.0))+"M";
else if(size>1024)
	fileSizeName=df.format(size/(1024.0))+"K";
else
	fileSizeName=size+"B";
jsonObject.put("fileSizeName",fileSizeName);
StringBuffer htmlStr = new StringBuffer();
if(!docid.equals("-1")){
	htmlStr.append("<div id='"+docid+"' class=\""+fileuuid+"\" class=''>");
	htmlStr.append("<div class='left m-t-3' style='background: url(/email/images/mailicon_wev8.png) -65px 0px  no-repeat ;width: 16px;height: 16px;'>&nbsp;</div>");
	htmlStr.append("<div class='left fileName p-b-3'  >"+filename+"</div>");
	htmlStr.append("<div class='left fileSize p-l-15' >("+fileSizeName+")&nbsp;&nbsp;&nbsp;&nbsp;<span class='new' style='color:green !important'>上传完成</span></div>");
	htmlStr.append("<div class='left p-l-15' ><a class='del'  href='javascript:doDelAcc("+docid+")'>"+SystemEnv.getHtmlLabelName(91, user.getLanguage())+"</a></div>");
	htmlStr.append("<div class='clear'></div>");
	htmlStr.append("</div>");
}
jsonObject.put("htmlStr",htmlStr.toString());
out.println("<script>parent.showDocinfo("+jsonObject.toString()+")</script>");
%>